import 'package:flutter/material.dart';
import 'package:kasax_demos2/day07_routes/detail_posts.dart';
import 'package:kasax_demos2/entry/data_posts_test.dart';
import 'package:kasax_demos2/entry/entrys.dart';
import 'package:kasax/utils/img_utils.dart';

/// 图片列表控件
class SampleRouteDemo extends StatefulWidget {
  const SampleRouteDemo({Key? key}) : super(key: key);

  @override
  _SampleRouteDemoState createState() => _SampleRouteDemoState();
}

class _SampleRouteDemoState extends State<SampleRouteDemo> {
  List<Posts> _list = PostsDatas.TEST_POSTS;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.all(10),
        child: ListView.separated(
            itemBuilder: (context, index) {
              var info = _list[index];
              return FlatButton(
                  padding: EdgeInsets.all(0),
                  onPressed: () {
                    Navigator.of(context).push(MaterialPageRoute(
                        builder: (context) => PostDetailPage(info)));
                  },
                  child: ImageUtils.buildRoundImgByClipRRect(
                      16 / 9, 8.0, "${info.imageUrl}"));
            },
            separatorBuilder: (context, index) {
              return Divider();
            },
            itemCount: _list.length),
      ),
    );
  }
}
